import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-09-14
 * Time: 21:07
 */
public class test {
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);

        String str_0 = scan.nextLine();
        String[] line_list_0 = str_0.trim().split(" ");
        ArrayList<Integer> arr = new ArrayList<>();
        for(int i = 0; i < line_list_0.length; i++){
            arr.add(Integer.parseInt(line_list_0[i]));
        }


        scan.close();

        int result = solution(arr);

        System.out.println(result);

    }

    public static int solution(ArrayList<Integer> arr){
        int result = 0;

        for (int i = 1 ; i <= arr.get(0); i++){
            int a = i;
            while(a > 0){
                int b = a % 10;
                if (b == arr.get(1)){
                    result++;
                }
                a = a / 10;
            }
        }

        return result;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str_0 = scan.nextLine().trim();
        int n = Integer.parseInt(str_0);

        scan.close();

        int result = solution(n);

        System.out.println(result);

    }

    public static int solution(int n){
        int result = -1;

        // TODO: 请在此编写代码
        for(int i = n / 8; i >= 0; i--){
            int a = n - i * 8;
            if(a % 6 == 0){
                result = i + a / 6;
            }
        }

        return result;
    }
}
